package indi.defoliation.unknownrpg.api.config;

import java.util.Map;
import java.util.Map.Entry;

import org.bukkit.plugin.java.JavaPlugin;

import indi.defoliation.unknownrpg.api.attribute.Attribute;
import indi.defoliation.unknownrpg.api.config.YamlConfigurer;

public class AttributeYamlConfig {
	
	private YamlConfigurer config;
	
	public AttributeYamlConfig(JavaPlugin plugin) {
		config =new YamlConfigurer(plugin,"AttributeConfig.yml");
	}
	
	public void addAttribute(Attribute att,Map<String,Object> map) {
		for(Entry<String,Object> entry : map.entrySet()) {
			if(config.contains(getKey(att,entry.getKey())))continue;
			config.set(getKey(att,entry.getKey()), entry.getValue());
		}
	}
	
	private String getKey(Attribute att,String key) {
		return att.getKeyName()+"."+key;
	}
	
	public void save() {
		config.save();
	}
	
	public <T> T get(Attribute att,String key) {
		return config.get(getKey(att,key));
	}
	
	public void reload() {
		config.reload();
	}
}
